local dataset = "$dataset" 
local sampletext = "$samplenametext"
local samplenamefile = "$samplenamefile"

clear

tempfile t1 base
clear
set obs 1
generate drop_me = 1
save `base', replace
foreach fe in y yn ycn {
	foreach bspec in 2 3 {

		use "$results_fold/`dataset'"

		keep if bs==0

		keep diff_tfpr_b`bspec'_`fe' dif_d_bar_b`bspec'_`fe' dif_a_bar_b`bspec'_`fe' dif_cov_stay_b`bspec'_`fe' dif_var_adj_b`bspec'_`fe' adding_term_b`bspec'_`fe' drop_term_b`bspec'_`fe'

		generate alt_diff_tfpr_b`bspec'_`fe' =  dif_d_bar_b`bspec'_`fe' + dif_a_bar_b`bspec'_`fe' + dif_cov_stay_b`bspec'_`fe' + dif_var_adj_b`bspec'_`fe' + adding_term_b`bspec'_`fe' + drop_term_b`bspec'_`fe'

		generate tester = diff_tfpr_b`bspec'_`fe' - alt_diff_tfpr_b`bspec'_`fe' 

		sum tester

		generate meanE = ((dif_d_bar_b`bspec'_`fe' + dif_a_bar_b`bspec'_`fe')/diff_tfpr_b`bspec'_`fe')*100

		generate MP = ((dif_cov_stay_b`bspec'_`fe' + dif_var_adj_b`bspec'_`fe' + adding_term_b`bspec'_`fe' + drop_term_b`bspec'_`fe')/diff_tfpr_b`bspec'_`fe')*100

		generate incumbent = ((dif_d_bar_b`bspec'_`fe' + dif_a_bar_b`bspec'_`fe' + dif_cov_stay_b`bspec'_`fe')/diff_tfpr_b`bspec'_`fe')*100

		generate extensive = (( dif_var_adj_b`bspec'_`fe' + adding_term_b`bspec'_`fe' + drop_term_b`bspec'_`fe')/diff_tfpr_b`bspec'_`fe')*100

		sum meanE MP incumbent extensive 

		keep meanE incumbent extensive MP

		foreach variable in meanE incumbent extensive MP {
			replace `variable' = round(`variable', 0.01)
		}

		generate spec = "`bspec'" + "`fe'"

		save `t1', replace

		clear 

		use `base'
		append using `t1'
		save `base', replace

	}
}

drop if drop_me==1
drop drop_me

keep if spec=="2y" | spec=="2yn" | spec=="3ycn" 

rename meanE V1
rename incumbent V2
rename extensive V3
rename MP V4


reshape long V, i(spec) j(statistic)

reshape wide V, i(statistic) j(spec) string

generate  value = "meanE" if statistic==1
replace value = "incumbent" if statistic==2
replace  value = "extensive" if statistic==3
replace  value = "MP" if statistic==4

graph bar V2y V2yn V3ycn, over(statistic,  relabel(1 "Mean Incumbent" 2 "Incumbent All" 3 "Extensive Margin" 4 "Multi-product")) scheme(s1color) blabel(total) ///
legend(order(1 "Year FE" 2 "Industry and Year FE" 3 "Industry-Year FE")) ytitle("Percent Full TFPR Effect (%)")

*title("`sampletext'") 

 graph export "$figures/`samplenamefile'_percent_effects.png", as(png) replace width(1800) height(1000)
